var e = getApp();
const {
  getCodeList,
  createOrder,
  getOpenid
} = require('../../common/api/user')
const api = require('../../common/utils/request.js')

Component({
  properties: {
    show: {
      value: false,
      type: Boolean
    },
  },

  data: {
    mobile: ''
  },
  ready: function () {
    // this.setData({
    //   price: this.data.list[0].price
    // })

  },
  
  methods: {
    changeMobile(e){
      console.log(e,'eeeeeeeeeee')
      this.setData({
        mobile: e.detail.value
      })
    },
    buyNow() {
      console.log(this.data.openid, 'this.data.openid')
      var _this = this;
      api.post(createOrder, {
        pt_id: e.globalData.ptId,
        uid: wx.getStorageSync('yz_uid'),
        type: 3, // 1充值积分2充值金币3购买套餐
        taocan_id: this.data.taocan_id,
        pay_type: 1, //1微信支付2金币支付 （只有买套餐有金币支付）
        openid: this.data.openid
      }).then(res => {
        //成功时回调函数
        console.log(res.errno, 'getCodeList')
        if (res.errno == 0) {
         
        }
      }).catch(err => {
        //失败时回调函数
        console.log(err)
      })
    },
    changeTaocan(e) {
      console.log(e.currentTarget.dataset.index, 'eeeeeeeeeeeee')
      var index = e.currentTarget.dataset.index;
      var item = e.currentTarget.dataset.item;
      this.setData({
        current: index,
        price: item.price,
        taocan_id: item.id
      })
    },
    cancelPop: function (t) {
      console.log(t);
      this.triggerEvent("closeShow");
      this.setData({
        show: false
      });
    },
    confirmPop(){
      this.triggerEvent("confirm",this.data.mobile);
    }
  }
});